import Vue from "vue";
import VueRouter from "vue-router";
import Home from "../views/Home.vue";
import AlbumDetail from "../views/AlbumDetail.vue";
import Recommend from "../views/Home/Recommend";
import Rank from "../views/Home/Rank";
import Search from "../views/Home/Search";
import PlayPage from "../views/PlayPage";

Vue.use(VueRouter);

const routerPush = VueRouter.prototype.push;
VueRouter.prototype.push = function(location) {
  return routerPush.call(this, location).catch((error) => error);
};

const routes = [
  {
    path: "/",
    name: "Home",
    component: Home,
    // 通过重定向，将 / 重定向到 /recommend,实现默认显示推荐页
    redirect: "/recommend",
    // 定义二级路由
    children: [
      {
        path: "recommend",
        name: "Recommend",
        component: Recommend,
      },
      {
        path: "rank",
        name: "Rank",
        component: Rank,
      },
      {
        path: "search",
        name: "Search",
        component: Search,
      },
    ],
  },
  {
    path: "/albumdetail/:id",
    name: "AlbumDetail",
    component: AlbumDetail,
  },
  {
    path: "/playpage/:id",
    name: "PlayPage",
    component: PlayPage,
  },
];

const router = new VueRouter({
  routes,
});

export default router;
